// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: [],
    lishi: [],
    searchval: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    this.setData({
      lishi: wx.getStorageSync('lishi') || []
    })
  },
  sousuo(e) {
    if (!e.detail) {
      this.setData({
        search: []
      })
    }
    let arr = wx.getStorageSync('lishi') || []
    if (arr.length >= 10) {
      arr.pop()
    }
    arr.push(e.detail)
    wx.setStorageSync('lishi', arr)
    this.setData({
      lishi: wx.getStorageSync('lishi') || []
    })


    console.log(e.detail);

    wx.request({
      url: 'https://www.uinav.com/api/public/v1/goods/qsearch',
      data: {
        query: e.detail
      },
      success: res => {
        console.log(res);
        this.setData({
          search: res.data.message
        })
      }
    })
  },
  sou(e) {
    this.setData({
      searchval: e.currentTarget.dataset.item
    })
    wx.request({
      url: 'https://www.uinav.com/api/public/v1/goods/qsearch',
      data: {
        query: e.currentTarget.dataset.item
      },
      success: res => {
        console.log(res);
        this.setData({
          search: res.data.message
        })
      }
    })
  },
  detail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/detail/detail?id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})